package com.zeyun.EasyOnlineShareCloud.common.convention.exception;


import com.zeyun.EasyOnlineShareCloud.common.convention.errorcode.IErrorCode;
import com.zeyun.EasyOnlineShareCloud.common.enums.ResultErrorCodeEnums;

import java.util.Optional;

/**
 * 服务端异常
 */
public class ServiceException extends AbstractException {

	public ServiceException(String message) {
		this(message, null, ResultErrorCodeEnums.SERVER_ERROR);
	}

	public ServiceException(IErrorCode errorCode) {
		this(null, errorCode);
	}

	public ServiceException(String message, IErrorCode errorCode) {
		this(message, null, errorCode);
	}

	public ServiceException(String message, Throwable throwable, IErrorCode errorCode) {
		super(Optional.ofNullable(message).orElse(errorCode.message()), throwable, errorCode);
	}

	@Override
	public String toString() {
		return "ServiceException{" +
				"code='" + errorCode + "'," +
				"message='" + errorMessage + "'" +
				'}';
	}
}

